# -*- coding: utf-8

# special value for paused status
PAUSE=1000

class Items(object):
  def __init__(self):
    self.array = []

  def __getitem__(self, index):
    return self.array[index]

  def append(self, topic):
    self.array.append( topic )
  
  def getall(self):
    return self.array
  
  def __len__(self):
    return len(self.array)

class Item(object):
  def __init__(self):
    self.id = None
    self.priority = None
    self.progress = 0
    self.duedate = None
    self.title = None
    self.note = None
    self.type = None
    self.exclude = False
  
  ATTR_INDEX_LIST = (
    lambda self: self.priority,
    lambda self: self.progress,
    lambda self: self.note,
    lambda self: self.title,
  )
  
  def __getitem__(self, index):
    "index expression for list column"
    return self.ATTR_INDEX_LIST[index](self)

  def IsTodoTopic(self):
    return self.priority and (not self.exclude)

  def getPriorityStr(self):
    return unicode( self.priority or u"" )

  def getProgressStr(self):
    if self.progress >= PAUSE:
      return "Paused"
    else:
      return unicode( self.progress ) + u"%"

  def __unicode__(self):
    return u"<Item [%d/%d] %s>" % (self.priority or -1, self.progress, self.title or u"None")

  def __repr__(self):
    return self.__unicode__()

